package com.cn.crmsystem.controller.customerController;

import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Visit;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.service.customerService.VisitService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@Api(value ="回访数据test",tags ="回访数据接口API")
public class VisitController {

    @Autowired
    private VisitService visitService;


    //获取登录的用户pojo对象
    //User user = (User) SecurityUtils.getSubject().getPrincipal();
    @ResponseBody
    @RequestMapping(value = "/insertVisit",method = RequestMethod.POST)
    @ApiOperation(value ="新增回访数据接口",notes = "填写回访基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "Visitortunity",value = "回访基本信息",required = false)
    public ResultJson insertVisit(@RequestBody Visit visit){
         Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return visitService.insertVisit(visit,login);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteVisit",method = RequestMethod.POST)
    @ApiOperation(value ="删除回访数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "回访数据id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson deleteVisit(Integer id){
        System.out.println(id);
        return visitService.deleteVisit(id);
    }

    @ResponseBody
    @RequestMapping(value = "/updateVisit",method = RequestMethod.POST)
    @ApiOperation(value ="修改回访数据接口",notes = "填写修改后回访基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "customer",value = "修改后回访基本信息",required = false)
    public ResultJson updateVisit(@RequestBody Visit visit) {
        //User user = (User) SecurityUtils.getSubject().getPrincipal();
        return visitService.updateVisit(visit);
    }

    @ResponseBody
    @RequestMapping(value = "/updateVisitUser",method = RequestMethod.POST)
    @ApiOperation(value ="修改回访负责人数据接口",notes = "传入修改后的负责人id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "修改后的负责人id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson updateVisitUser(@RequestParam Integer id) {
        return visitService.updateVisitUser(id);
    }

    @ResponseBody
    @RequestMapping(value = "/selectVisit",method = RequestMethod.POST)
    @ApiOperation(value ="条件查询回访数据接口",notes = "填写筛选条件数据",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "回访编号",paramType = "query",dataType = "Integer",required = false),
            @ApiImplicitParam(name = "customer_name",value = "客户名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "contract_id",value = "合同编号",paramType = "query",dataType = "Integer",required = false),
            @ApiImplicitParam(name = "user_name",value = "回访人名字",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "create_name",value = "创建人名字",paramType = "query",dataType = "String",required = false)
    })
    public ResultJson<List> selectVisit(@RequestBody @RequestParam  @ApiParam(required = false) Map<String,Object> map) {
        return visitService.selectVisit(map);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteAllVisit",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除回访数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "回访id",paramType = "query",dataType = "String",required = false)
    public ResultJson deleteAllVisit(Integer[] ids){
        System.out.println(ids.length);
        return visitService.deleteAllVisit(ids);

    }
}
